<template>
  <div
    v-loading="loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)">
    <!--搜索栏-->
    <div align="right">
      <my-button type="primary" :click="function (){create()}" access-action="ShopAddress/manage" text="新增"></my-button> &nbsp;&nbsp;
    </div>
    <common-list-table
      ref="myCommonListTable"
      :sitting="listTableSitting"
      :search-list="searchList">
      <template slot="actSlot" slot-scope="scope">
        <my-button type="success" :click="function (){edit(scope)}" text="编辑" access-action="ShopAddress/manage"></my-button>
        <my-button type="danger" :click="function (){del(scope)}" text="删除" access-action="ShopAddress/manage"></my-button>
      </template>
    </common-list-table>

  </div>
</template>

<script>


import CreateSysUserDialog from '../Dialog/CreateSysUserDialog'
import MyButton from '../Common/MyButton'

var fieldArr = DemoData.ShopAddress.field
export default {
  name: 'ShopAddressPage',
  components: {MyButton, },
  mounted () {
    // this.$refs.myCommonListTable.setListData(DemoData.SysUser.list)
    this.searchList()
  },
  data: function () {
    return {
      loading: false,
      // 搜索栏配置项
      searchSittingArray: Object.assign([], fieldArr),
      listTableSitting: {
        modelName: '地址管理',
        fieldArr: fieldArr,
        tableHeight: this.getTableHeight(),
        page: 1,
        pageSize: 20,
        actColumnWidth:200,
        defaultSort: {
          // prop:'username',
          // order:'descending',
        }
      }
    }
  },
  methods: {
    getTableHeight: function () {
      var height = this.getWinSize().height - 225
      return height > 500 ? height : 500
    },
    // 初始化查询
    searchList: function () {
      // 表格列表,查询参数
      var listTableForm = this.$refs.myCommonListTable.formData

      // 搜索栏,查询参数
      // var searchBarForm = this.$refs.commonListSearchBar.getFormData()

      var form = Object.assign({}, listTableForm)
      // 如果有默认排序 && 默认排序数据未设置,就进行查询请求(默认排序设置会触发查询)
      if (this.listTableSitting.defaultSort && this.listTableSitting.defaultSort.prop && this.$refs.myCommonListTable.formData.sortOrder === '') {
        return ''
      } else {

      }
      let $this = this
      $this.loading = true
      $this.MyRequest($this.ApiDoNameShop + 'ShopAddress/getList', form, function (data) {
        $this.$refs.myCommonListTable.setListData({
          total:1,
          list:data,
        })
        $this.loading = false
        $this.$forceUpdate()
      })
      // console.log('全部,查询参数',form)
    },
    create:function () {
      this.$router.push({
        name:'ShopAddressFormPage',
        query:{
          type:'create'
        }
      })
    },
    // 编辑地址
    edit:function (info) {
      this.$router.push({
        name:'ShopAddressFormPage',
        query:{
          id:info.rowInfo.id,
          type:'update'
        }
      })
    },
    // 删除地址
    del:function (info) {
      let $this=this
      $this.$confirm('您确认要进行该操作吗, 是否继续?', '系统提醒', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        $this.loading=true
        $this.MyRequest($this.ApiDoNameShop+'ShopAddress/delete',{id:info.rowInfo.id},function () {
          $this.loading=false
          $this.$message({
            type: 'success',
            message: '删除成功'
          });
          $this.searchList()
          $this.$forceUpdate()
        },function (res) {
          $this.$message.error(res.message)
          $this.loading=false
        })
      })
    },
  }
}
</script>

<style scoped>

</style>
